<?php

namespace app\admin\model\store;

use app\common\model\TimeModel;

class GoodsExchange extends TimeModel
{

    protected $name = "goods_exchange";

    protected $deleteTime = "delete_time";


    public function getIsStatusList()
    {
        return ['1' => '上架', '0' => '下架',];
    }

    public function getGoodsInfo()
    {
        $field = ['id', 'goods_name', 'image'];
        return $this->belongsTo(Goods::class, 'goods_id', 'id')->field($field);
    }

    public function getGoodsSkuInfo()
    {
        $field = ['id', 'goods_id', 'attr_values', 'sku_image', 'sku_price'];
        return $this->belongsTo(GoodsSku::class, 'sku_id', 'id')->field($field);

    }

    /**
     * 查询积分活动库存
     * auth : william
     * @param int $exchangeId 积分活动id
     * @return false|mixed
     */
    public static function getExangeStock(int $exchangeId)
    {
       $stock =self::where('id', $exchangeId)->value('stock');
       if (empty($stock)){
           return  false;
       }
       return $stock;
    }



}